const INPUT_SOURCE_TYPE_XKB = 'xkb';
const INPUT_SOURCE_TYPE_IBUS = 'ibus';
+// This is the longest we'll keep the keyboard frozen until an input
+// source is active.
+const MAX_INPUT_SOURCE_ACTIVATION_TIME = 4000; // ms
+
+const BUS_NAME = 'org.gnome.SettingsDaemon.Keyboard';
+const OBJECT_PATH = '/org/gnome/SettingsDaemon/Keyboard';
+
+const KeyboardManagerInterface =
+<interface name="org.gnome.SettingsDaemon.Keyboard">
+<method name="SetInputSource">
+ <arg type="u" direction="in" />
+</method>
+</interface>;
+
+const KeyboardManagerProxy = Gio.DBusProxy.makeProxyWrapper(KeyboardManagerInterface);
+
+function releaseKeyboard() {
+ if (Main.modalCount > 0)
+ global.display.unfreeze_keyboard(global.get_current_time());
+ else
+ global.display.ungrab_keyboard(global.get_current_time());
+}
+
+function holdKeyboard() {
+ global.freeze_keyboard(global.get_current_time());
+}
+
const IBusManager = new Lang.Class({
Name: 'IBusManager',
this._ibusManager.connect('property-updated', Lang.bind(this, this._ibusPropertyUpdated));
this._inputSourcesChanged();
+ this._keyboardManager = new KeyboardManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
+ function(proxy, error) {
+ if (error)
+ log(error.message);
+ });
+ this._keyboardManager.g_default_timeout = MAX_INPUT_SOURCE_ACTIVATION_TIME;
+
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this._showLayoutItem = this.menu.addAction(_("Show Keyboard Layout"), Lang.bind(this, this._showLayout));
let is = new InputSource(type, id, displayName, shortName, i);
is.connect('activate', Lang.bind(this, function() {
- if (this._currentSource && this._currentSource.index == is.index)
- return;
- this._settings.set_value(KEY_CURRENT_INPUT_SOURCE,
- GLib.Variant.new_uint32(is.index));
+ holdKeyboard();
+ this._keyboardManager.SetInputSourceRemote(is.index, releaseKeyboard);
}));
if (!(is.shortName in inputSourcesByShortName))
meta_plugin_end_modal (global->plugin, timestamp);
}
+void
+shell_global_freeze_keyboard (ShellGlobal *global,
+ guint32 timestamp)
+{
+ meta_display_freeze_keyboard (global->meta_display, global->stage_xwindow, timestamp);
+}
+
/* Code to close all file descriptors before we exec; copied from gspawn.c in GLib.
*
* Authors: Padraig O'Briain, Matthias Clasen, Lennart Poettering